//
//  XVisitorView.m
//  XWeibo-OC
//
//  Created by Apple on 15/10/26.
//  Copyright © 2015年 Apple. All rights reserved.
//

#import "XVisitorView.h"

@interface XVisitorView ()


//转轮
@property(nonatomic,weak) UIImageView *wheelView;
//小房子
@property(nonatomic,weak) UIImageView *houseView;
//文字
@property(nonatomic,weak) UILabel *messageLabel;
//注册按钮
@property(nonatomic,weak) UIButton *registerBtn;
//登录按钮
@property(nonatomic,weak) UIButton *loginBtn;




@end

@implementation XVisitorView


- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame])
    {
        [self setupSubView];
        [self perpareUI];
    
    }
    return self;
}

#pragma mark - 创建子控件
- (void)setupSubView
{
    //转轮
    UIImageView *wheelView = [[UIImageView alloc] init];
    wheelView.image = [UIImage imageNamed:@"visitordiscover_feed_image_smallicon"];
    [wheelView sizeToFit];
    [self addSubview:wheelView];
    self.wheelView = wheelView;
    self.link = [CADisplayLink displayLinkWithTarget:self selector:@selector(updateRomatationWithWheelView)];
    [self.link addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];

    
    //小房子
    UIImageView *houseView = [[UIImageView alloc] init];
    houseView.image = [UIImage imageNamed:@"visitordiscover_feed_image_house"];
    [houseView sizeToFit];
    [self addSubview:houseView];
    self.houseView = houseView;
    
    //文字
    UILabel *messageLabel = [[UILabel alloc] init];
    messageLabel.text = @"关注一些人,看看有什么惊喜.";
    messageLabel.textColor = [UIColor lightGrayColor];
    messageLabel.numberOfLines = 0;
    [messageLabel sizeToFit];
    [self addSubview:messageLabel];
    self.messageLabel = messageLabel;
    
    //注册按钮
    UIButton *registerBtn = [[UIButton alloc] init];
    [registerBtn setBackgroundImage:[UIImage imageNamed:@"common_button_white_disable"] forState:UIControlStateNormal];
    [registerBtn setTitle:@"注册" forState:UIControlStateNormal];
    [registerBtn setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
    [self addSubview:registerBtn];
    [registerBtn sizeToFit];
    self.registerBtn = registerBtn;
    
    //登录按钮
    UIButton *loginBtn = [[UIButton alloc] init];
    [loginBtn setBackgroundImage:[UIImage imageNamed:@"common_button_white_disable"] forState:UIControlStateNormal];
    [loginBtn setTitle:@"登录" forState:UIControlStateNormal];
    [loginBtn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [self addSubview:loginBtn];
    [loginBtn sizeToFit];
    self.loginBtn = loginBtn;
    
}


#pragma mark - 布局子控件
- (void)perpareUI
{
//    [super layoutSubviews];
    
    self.wheelView.translatesAutoresizingMaskIntoConstraints = NO;
    self.houseView.translatesAutoresizingMaskIntoConstraints = NO;
    self.messageLabel.translatesAutoresizingMaskIntoConstraints = NO;
    self.registerBtn.translatesAutoresizingMaskIntoConstraints = NO;
    self.loginBtn.translatesAutoresizingMaskIntoConstraints = NO;
    
    //转轮
    [self addConstraint:[NSLayoutConstraint constraintWithItem:self.wheelView attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeCenterX multiplier:1 constant:0]];
    [self addConstraint:[NSLayoutConstraint constraintWithItem:self.wheelView attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeCenterY multiplier:1 constant:-40]];
    
    
    //小房子
    [self addConstraint:[NSLayoutConstraint constraintWithItem:self.houseView attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.wheelView attribute:NSLayoutAttributeCenterX multiplier:1 constant:0]];
    [self addConstraint:[NSLayoutConstraint constraintWithItem:self.houseView attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.wheelView attribute:NSLayoutAttributeCenterY multiplier:1 constant:0]];
    
    //文字
    [self addConstraint:[NSLayoutConstraint constraintWithItem:self.messageLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.wheelView attribute:NSLayoutAttributeBottom multiplier:1 constant:16]];
    
    [self addConstraint:[NSLayoutConstraint constraintWithItem:self.messageLabel attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.wheelView attribute:NSLayoutAttributeCenterX multiplier:1 constant:0]];
    [self.messageLabel addConstraint:[NSLayoutConstraint constraintWithItem:self.messageLabel attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:240]];
    
    //注册按钮
    [self addConstraint:[NSLayoutConstraint constraintWithItem:self.registerBtn attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.messageLabel attribute:NSLayoutAttributeLeft multiplier:1 constant:0]];
    [self addConstraint:[NSLayoutConstraint constraintWithItem:self.registerBtn attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.messageLabel attribute:NSLayoutAttributeBottom multiplier:1 constant:16]];
    [self.registerBtn addConstraint:[NSLayoutConstraint constraintWithItem:self.registerBtn attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:0 constant:100]];
    [self.registerBtn addConstraint:[NSLayoutConstraint constraintWithItem:self.registerBtn attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:0 constant:35]];
    
    //登录按钮
    [self addConstraint:[NSLayoutConstraint constraintWithItem:self.loginBtn attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.messageLabel attribute:NSLayoutAttributeBottom multiplier:1 constant:16]];
    [self addConstraint:[NSLayoutConstraint constraintWithItem:self.loginBtn attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.messageLabel attribute:NSLayoutAttributeRight multiplier:1 constant:0]];
    [self.loginBtn addConstraint:[NSLayoutConstraint constraintWithItem:self.loginBtn attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:0 constant:100]];
    [self.loginBtn addConstraint:[NSLayoutConstraint constraintWithItem:self.loginBtn attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:0 constant:35]];

    
}


- (void)updateRomatationWithWheelView
{
    static NSInteger index = 1;
    self.wheelView.layer.transform = CATransform3DMakeRotation(index * M_PI / 180, 0, 0, 1);
    NSLog(@"");
    index++;
}






@end
